package com.timesheet.gui.efforttracker.views;

import com.timesheet.gui.efforttracker.composite.SectionEffortComposite;
import com.timesheet.gui.efforttracker.composite.TabsComposite;
import com.timesheet.gui.forms.FormView;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;

/**
 * This sample class demonstrates how to plug-in a new workbench view. The view shows data obtained from the model. The
 * sample creates a dummy model on the fly, but a real implementation would connect to the model available either in
 * this or another plug-in (e.g. the workspace). The view is connected to the model using a content provider.
 * <p>
 * The view uses a label provider to define how model objects should be presented in the view. Each view can present the
 * same model objects using different labels and icons, if needed. Alternatively, a single label provider can be shared
 * between views in order to ensure that objects of the same type are presented in the same way everywhere.
 * <p>
 */

public class EffortTrackerView extends FormView {

	/**
	 * The ID of the view as specified by the extension.
	 */
	public static final String ID = "com.timesheet.gui.efforttracker.views.EffortTrackerView";

	private TableViewer viewer;

	private Action action1;

	private Action action2;

	private Action doubleClickAction;

	private IAction action3;

	/**
	 * The constructor.
	 */
	public EffortTrackerView() {
	}

	/**
	 * This is a callback that will allow us to create the viewer and initialize it.
	 */
	@Override
	public void createPartControl(Composite parent) {
		//super.createPartControl(parent);
		parent.setLayout(new FillLayout());

	/*	Composite container = getForm().getBody();
		getForm().setText("ss");
		getToolkit().decorateFormHeading(getForm());
		getToolkit().paintBordersFor(container);
		container.setLayout(new RowLayout());*/
		//container.setLayout(new GridLayout(1, false));

		/*SectionEffortComposite sectionEffortComposite = new SectionEffortComposite(container, SWT.NONE);
		sectionEffortComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));*/
		
		TabsComposite tabsComposite = new TabsComposite(parent, SWT.NONE);
		tabsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		//formToolkit.adapt(sectionEffortComposite);
		//formToolkit.paintBordersFor(sectionEffortComposite);
		
		
		

		makeActions();
		contributeToActionBars();

	}

	

	private void contributeToActionBars() {
		IActionBars bars = getViewSite().getActionBars();
		// fillLocalPullDown(bars.getMenuManager());
		fillLocalToolBar(bars.getToolBarManager());
	}

	private void fillLocalPullDown(IMenuManager manager) {
		manager.add(action1);
		manager.add(new Separator());
		manager.add(action2);
		manager.add(new Separator());
		manager.add(action3);
	}

	private void fillContextMenu(IMenuManager manager) {
		manager.add(action1);
		manager.add(action2);
		// Other plug-ins can contribute there actions here
		manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
	}

	private void fillLocalToolBar(IToolBarManager manager) {
		manager.add(action1);
		manager.add(action2);
		manager.add(action3);
	}

	private void makeActions() {
		action1 = new Action() {

			public void run() {

			}
		};
		action1.setText("Action 1");
		action1.setToolTipText("Action 1 tooltip");
		action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
				.getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));

		action2 = new Action() {

			public void run() {
				System.out.println("hihihi");

				try {
					PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
							.showView("com.timesheet.gui.efforttracker.EffortsWSRView");
				}
				catch (PartInitException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				//ViewEffortWeekWindow effortWeekWindow = new ViewEffortWeekWindow();
				//	effortWeekWindow.getText().setText(result);
				//effortWeekWindow.open();
			}
		};
		action2.setText("WSR");
		action2.setToolTipText("WSR");
		action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
				.getImageDescriptor(ISharedImages.IMG_OBJ_FOLDER));

		action3 = new Action() {

			public void run() {
				System.out.println("hihihi");

				try {
					PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
							.showView("com.timesheet.gui.efforttracker.EffortsWSRView");
				}
				catch (PartInitException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				//ViewEffortWeekWindow effortWeekWindow = new ViewEffortWeekWindow();
				//	effortWeekWindow.getText().setText(result);
				//effortWeekWindow.open();
			}
		};
		action3.setText("Show Daily Efforts");
		action3.setToolTipText("Show Daily Efforts");
		action3.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
				.getImageDescriptor(ISharedImages.IMG_ETOOL_HOME_NAV));

	}

	private void hookDoubleClickAction() {
		viewer.addDoubleClickListener(new IDoubleClickListener() {

			public void doubleClick(DoubleClickEvent event) {
				doubleClickAction.run();
			}
		});
	}

	/**
	 * Passing the focus request to the viewer's control.
	 */
	public void setFocus() {

	}
}